<!DOCTYPE html>
<html lang="en">

    <head>

        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <meta name="description" content="">
        <meta name="author" content="">

        <title>Kura's Hardware Shop Login Page</title>

        <!-- Bootstrap Core CSS -->
        <link href="css/bootstrap.min.css" rel="stylesheet">

        <!-- MetisMenu CSS -->
        <link href="css/plugins/metisMenu/metisMenu.min.css" rel="stylesheet">

        <!-- Custom CSS -->
        <link href="css/sb-admin-2.css" rel="stylesheet">

        <!-- Custom Fonts -->
        <link href="font-awesome-4.1.0/css/font-awesome.min.css" rel="stylesheet" type="text/css">

        <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
        <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
        <!--[if lt IE 9]>
            <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
            <script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
        <![endif]-->

    </head>

    <body>
        <?php
        session_start();
        if (isset($_SESSION['role'])) {
            header("Location: info.php");
        }
        include_once("./script/dbconnect.php");
        if (isset($_POST['submit'])) {
			$email = $_POST['email'];
			$pass = md5($_POST['password']);
			if ($email != "" && $pass != "") {
				$result = mysqli_query(getConnect(), "select id,role,name from users where email= '" . $email . "' and password= '" . $pass . "'") or die(mysql_error());
			}
		}
        ?>
        <div class="container">
            <div class="row">
                <div class="col-md-4 col-md-offset-4">
                    <div class="login-panel panel panel-default">
                        <div class="panel-heading">
                            <h3 class="panel-title">Please Sign In</h3>
                        </div>
                        <div class="panel-body">
                            <form role="form" method="POST">
                                <fieldset>
                                    <div class="form-group">
                                        <input class="form-control" placeholder="E-mail" name="email" type="email" autofocus>
                                    </div>
                                    <div class="form-group">
                                        <input class="form-control" placeholder="Password" name="password" type="password" value="">
                                    </div>
                                    <!-- Change this to a button or input when using this as a form -->

                                    <?php
                                    if (isset($_POST['submit']) && $result != null) {
                                        if (mysqli_num_rows($result) == 0) {
                                            echo "<div class = 'panel panel-red'>";
                                            echo "<div class = 'panel-heading'>";
                                            echo"User and Password mismatch";
                                            echo "</div>";
                                            echo "</div>";
                                        } else {
                                            $row = mysqli_fetch_array($result);
                                            $_SESSION['role'] = $row['role'];
                                            $_SESSION['name'] = $row['name'];
                                            $_SESSION['uid'] = $row['id'];
                                            $_SESSION['id'] = $row['id'];
                                            header("Location: info.php");
                                        }
                                    }
                                    ?>

                                    <input name="submit" type="submit" class="btn btn-lg btn-success btn-block" value="Login  ">

                                </fieldset> 

                            </form>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <!-- jQuery Version 1.11.0 -->
        <script src="js/jquery-1.11.0.js"></script>

        <!-- Bootstrap Core JavaScript -->
        <script src="js/bootstrap.min.js"></script>

        <!-- Metis Menu Plugin JavaScript -->
        <script src="js/plugins/metisMenu/metisMenu.min.js"></script>

        <!-- Custom Theme JavaScript -->
        <script src="js/sb-admin-2.js"></script>

    </body>

</html>